package org.example.day12;

import java.text.SimpleDateFormat;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 5.1.1.1 方法schedule(TimerTask task,long delay)
 *      ①计划时间在未来
 */
public class MyThread7 {
    //将new Timer()时创建的任务线程设置为守护线程.主线程执行结束后,守护线程直接die.
//    private static Timer timer = new Timer(true);
    private static Timer timer = new Timer();

    static public class MyTask extends TimerTask {
        @Override
        public void run() {
            System.out.println("运行了！时间为: " + System.currentTimeMillis());
        }
    }

    public static void main(String[] args) {
        MyTask task = new MyTask();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前时间: " + System.currentTimeMillis());
        //延迟4s后开始执行
        timer.schedule(task, 4000);
    }
}
